<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/img/admin.png}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>TeamA6| 商品SKU管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" th:href="@{/administration/adminlte/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/administration/adminlte/bower_components/font-awesome/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/administration/adminlte/bower_components/Ionicons/css/ionicons.min.css}">
    <link rel="stylesheet" th:href="@{/administration/bootstrap-table/bootstrap-table.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/administration/adminlte/css/AdminLTE.min.css}">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="@{/administration/adminlte/css/skins/_all-skins.min.css}">

    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>




    <script th:src="@{/administration/adminlte/bower_components/jquery/dist/jquery.min.js}"></script>
    <script th:src="@{/administration/adminlte/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
    <!-- FastClick -->
    <script th:src="@{/administration/adminlte/bower_components/fastclick/lib/fastclick.js}"></script>
    <!-- AdminLTE App -->
    <script th:src="@{/administration/adminlte/js/adminlte.min.js}"></script>
    <!-- AdminLTE for demo purposes -->
    <script th:src="@{/administration/adminlte/js/demo.js}"></script>


    <script th:src="@{/administration/bootstrap-table/bootstrap-table.min.js}"></script>
    <script th:src="@{/administration/bootstrap-table/locale/bootstrap-table-zh-CN.js}"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<!--    引入公共类头部文件-->
    <div th:replace="administration/common/bar::topbar"></div>
    <!-- 左侧菜单页面-->

    <div th:replace="administration/common/bar::#sidebar"></div>

    <!--不能抽取的内容显示页-->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                网上购物商城
                <small>后台管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">商品模块</a></li>
                <li class="active">商品SKU管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <div class="box-body">
                            <div id="toolbar">
                                <div class="form-inline" role="form">
                                    <div class="form-group">
                                        <label for="keyword">Keyword: </label>
                                        <input name="keyword" class="form-control" type="text" id="keyword">
                                    </div>
                                    <button id="searchBtn" type="submit" class="btn btn-primary" style="margin-left: 5px">
                                        查询
                                    </button>
                                    <a href="/adminSku/addSkuShow">
                                        <button id="createBtn" type="submit" class="btn btn-info" style="margin-left: 30px">
                                            录入
                                        </button>
                                    </a>
                                    <button id="deleteBtn" type="submit" class="btn btn-danger">删除</button>
                                </div>
                            </div>
                            <table id="dataTable" class="table table-hover table-responsive"
                                   style="table-layout: fixed"></table>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>

    <!--尾部代码-->
    <div th:replace="administration/common/bar :: #footerbar"></div>

    <!--控制代码-->
    <!--<div th:replace="administration/common/bar :: #controlbar"></div>-->
</div>
<script>
    $('#dataTable').bootstrapTable({
        method: 'get',
        url: "/adminSku/api/skuList",
        toolbar: '#toolbar',
        striped: true,
        dataField: "skus",
        pageNumber: 1,
        pagination: true,
        queryParamsType: 'limit',
        queryParams:queryParams,
        sidePagination: 'server',
        pageSize: 20,
        pageList: [10, 20, 50, 100],
        showRefresh: true,
        clickToSelect: true,
        toolbarAlign: 'left',
        buttonsAlign: 'right',
        showColumns: true,
        columns: [
            {
                title: '全选',
                field: 'select',
                checkbox: true,
                width: 25,
                align: 'center',
            },
            {
                title: '商品SKUID',
                field: 'skuId',
                visible: false,
                width: 160
            },
            {
                title: '商品ID',
                field: 'productId',
                visible: false,
                width: 160,
                align: 'center'
            },
            {
                title: '商品名称',
                field: 'productName',
                width: 160,
                align: 'center'
            },
            {
                title: '商品颜色',
                field: 'color',
                width: 160,
                align: 'center'
            },
            {
                title: '商品尺码',
                field: 'size',
                width: 160,
                align: 'center'

            },
            // {
            //     title: '商品数量',
            //     field: 'num',
            //     width: 160,
            //     align: 'center'
            // },
            {
                title: '图片路径',
                field: 'imgSrc',
                width: 160,
                align: 'center'
            },
            {
                title: '编辑',
                width: 50,
                formatter: function (value, row, index, field) {
                    return [
                        '<a class="edit ml10" href="javascript:void(0)" title="Edit">',
                        '<i class="glyphicon glyphicon-edit"></i>',
                        '</a>',
                    ].join('');
                },
                events: {
                    'click .edit': function (e, value, row, index) {
                        window.location.href = '/adminSku/editSkuShow?skuId=' + row.skuId+'&color=' + row.color + '&size=' +row.size +'&imgSrc=' +row.imgSrc+'&productId=' +row.productId ;
                    }
                },
                align: 'center'
            },
            {
                title: '删除',
                width: 50,
                formatter: function (value, row, index, field) {
                    return [
                        '<a class="edit ml10" href="javascript:void(0)" title="Delete">',
                        '<i class="glyphicon glyphicon glyphicon-remove"></i>',
                        '</a>',
                    ].join('');
                },
                events: {
                    'click .edit': function (e, value, row, index) {
                        if (confirm("确定要删除吗")) {
                            window.location.href = '/adminSku/deleteSku?skuId=' + row.skuId;
                        }
                        // layer.confirm('确定删除吗？', function (index) {
                        //     $.ajax({
                        //         url: '/adminSku/deleteSku?skuId=' + row.skuId,
                        //         data: {
                        //             skuId: row.skuId
                        //         },
                        //         method: 'GET',
                        //         traditional: true,
                        //         success: function (json) {
                        //             layer.msg('已删除');
                        //         }
                        //     });
                        // });

                    }
                },
                align: 'center'
            }
            
        ],
        locale: 'zh-CN',
        responseHandler: function (data) {
            return data;
        }
    });
    function queryParams(params) {
        return {
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            keyword: $("#keyword").val()
        }
    }
    $(document).ready(function () {
        $("#searchBtn").click(function () {
            $("#dataTable").bootstrapTable('refresh');
        })
        $("#deleteBtn").click(function () {
            $("#dataTable").bootstrapTable('refresh');
        })
    })
    $('#deleteBtn').on("click", function(){
        if (!confirm("是否确认删除？"))
            return;
        var rows = $("#dataTable").bootstrapTable('getSelections');// 获得要删除的数据
        if (rows.length == 0) {// rows 主要是为了判断是否选中，下面的else内容才是主要
            alert("请先选择要删除的记录!");
            return;
        } else {
            var skus = new Array();// 声明一个数组
            $(rows).each(function() {// 通过获得别选中的来进行遍历
                skus.push(this.skuId);// cid为获得到的整条数据中的一列
            });
            console.log(skus);
            deleteMs(skus)
        }
    })
    function deleteMs(skus) {
        $.ajax({
            url :"/adminSku/batchDelete",
            data : "skus=" + skus,
            type : "post",
            dataType : "json",
            // success : function(data) {
            //     console(data);
            //     alert(data);
            //     $("#dataTable").bootstrapTable('refresh');
            // }
        });
    }
</script>
</body>
</html>
